#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <ctime>
#include "RingQueue.hpp"
// #include "Task.hpp"

using namespace std;


void *Producer(void *args)
{
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);
    int i = 0;
    while(true)
    {
        rq->Push(i);
        cout<<"生成一个i = "<<i++<<endl;
    }
    return nullptr;

}
void *Consumer(void *args)
{
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);
    while(true)
    {
        int value;
        rq->Pop(&value);
        cout<<"消费了一个数据 = "<<value<<endl;
        sleep(1);
    }
    return nullptr;
}




int main()
{
    RingQueue<int> *rq = new RingQueue<int>();

    pthread_t p,c;

    for(int i = 0; i<5;i++)
    {
        pthread_create(&p,nullptr,Producer,rq);
    }

    for(int i = 0; i<5;i++)
    {
        pthread_create(&c,nullptr,Consumer,rq);
    }
    
    for(int i = 0; i<5;i++)
    {
        pthread_join(p, nullptr);
    }
    
    for(int i = 0; i<5;i++)
    {
        pthread_join(c, nullptr);
    }
    
    return 0;
}